#include "chartscene.h"
#include <QDebug>
#include <QTextDocument>
#include <qwt.h>
#include <QVector>
#include <QPointF>
#include "scaledraw.h"

/*Test values*/
#define MAXVAL 10000
#define MINVAL 1000

/*init chartScene*/
ChartScene::ChartScene(QObject *parent):
    QwtPlotCurve()
{

   /* QVector<QPointF> v;
    v.append(QPointF(0,5856.76));
    v.append(QPointF(1,5800.68));
    v.append(QPointF(2,6000.68));
    setSamples(v);
    this->show();*/



    setMaxValues(MAXVAL,MAXVAL);
    setMinValues(MINVAL,MINVAL);
   // drawAxes(AXES_STEPS);

    /*test lines
    qDebug()<<"Scaled point (0,0): "<<getScaledPoint(0,0);
    addChartLine(getScaledPoint(0,0),getScaledPoint(MAXVAL,MAXVAL));
    addChartLine(getScaledPoint(0,MAXVAL),getScaledPoint(MAXVAL,MAXVAL));
    addChartLine(getScaledPoint(MAXVAL,MAXVAL),getScaledPoint(MAXVAL,0));*/
}

void ChartScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    qDebug()<<"POS: "<<event->lastScenePos();
}

/*set the max values for scaling*/
void ChartScene::setMaxValues(const qreal &max_x, const qreal &max_y)
{
    maxx=max_x;
    maxy=max_y;
}

/*set min values for scaling*/
void ChartScene::setMinValues(const qreal &min_x, const qreal &min_y)
{
    minx=min_x;
    miny=min_y;
}

void ChartScene::drawGraph(QwtPlot *plot, const QList<QPointF> & pointList)
{
    attach(plot);
    plot->setAxisScaleDraw(2,new ScaleDraw());  //convert the x-axis labels
    setSamples(pointList.toVector());
    this->show();
}

void ChartScene::drawGraph(QwtPlot* plot,const QList<qreal>& xvals,const QList<qreal>& yvals)
{

    attach(plot);

    plot->setAxisScaleDraw(2,new ScaleDraw());  //convert the x-axis labels

    QVector<QPointF> v;

    for(int i=0;i<yvals.size();i++)
    {
        v.append(QPointF(i,yvals.at(i)));
    }
    qDebug()<<"Setting up samples: "<<v;
    setSamples(v);
    this->show();
}
